; http://code.google.com/p/springer-loader/
; by Ritterbrater
; June 2012
; GNU GPL V3
; file created with notepad2

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

checkexistence("config.ini")
checkexistence("wget.ini")
checkexistence("wget.exe")
checkexistence("httrack.exe")
checkexistence("gunzip.exe")
checkexistence("zlib1.dll")
checkexistence("libhttrack.dll")

;Beginning UI

Gui, Add, Text, x16 y24 w400 h15 , Add links (Browse This Book -> Contents), seperate with return:
Gui, Add, Edit, x16 y43 w430 h340 , 
Gui, Add, Button, x356 y400 w90 h30 , Go!
Gui, Add, Text, x16 y400 w185 , You accept Terms of Service of Springerlink, HTTrack, Wget, GZip and SpringerLoader
Gui, Add, Text,  , Select downloader:
Gui, Add, Radio, checked vRadios, HTTrack (recommended)
Gui, Add, Radio, , wget (alternative downloader, free configurable)
;Gui, Add, Radio, , experimental Downloader (requires .NET Framework 2.0 or later) ;not yet implemented yet; wget seems to work
Gui, Add, CheckBox, x212 y400 w100 h30 , debug mode
Gui, Add, CheckBox, , check access
; Generated using SmartGUI Creator 4.0
Gui +Resize
Gui, Show, x246 y195 h520 w470, SpringerLoader 1.4.5
Return

ButtonGo!:

ControlGetText, urls, Edit1
gui, submit
controlget, debugswitch, checked, , debug mode
controlget, accessswitch, checked, , check access
Gui, Destroy
sleep, 100 ;give time to destroy gui
dummy:=createdownloadcommand("", "", "", Radios)
getdebugstatus(debugswitch)
checkaccess("", "", "", accessswitch)
startdownloading(urls)
;do sth
exitapp

GuiClose:
ExitApp
 

startdownloading(urls)
{

  filedelete, %a_scriptdir%\index-2.html 
  filedelete, %a_scriptdir%\index-2.html.gz
  filedelete, %a_scriptdir%\index-2.html.readme 
  filedelete, %a_scriptdir%\index.html 
  filedelete, %a_scriptdir%\contents 
  filedelete, %a_scriptdir%\cookies.txt 
  filedelete, %a_scriptdir%\fulltext*.pdf*
  
  ;licensetest()
  
  filedelete, %a_scriptdir%\index-2.html 
  filedelete, %a_scriptdir%\index-2.html.gz
  filedelete, %a_scriptdir%\index-2.html.readme 
  filedelete, %a_scriptdir%\index.html 
  filedelete, %a_scriptdir%\contents 
  
  SetWorkingDir %A_ScriptDir%

  iniread, par1, %a_scriptdir%\config.ini, Options, launchparameters1, ERROR
  iniread, par2, %a_scriptdir%\config.ini, Options, launchparameters2, ERROR

  iniread, showballoon, %a_scriptdir%\config.ini, Options2, showballoontip, ERROR
  iniread, showfinished, %a_scriptdir%\config.ini, Options2, showfinishedbox, ERROR
  iniread, loggingvar, %a_scriptdir%\config.ini, Options2, logging, ERROR ;default value
  iniread, par, %a_scriptdir%\config.ini, Options2, filelength, ERROR ;default value
  
  debugmsg("launchparameters1: " . par1 . "`n"  
    . "launchparameters2: " . par2 . "`n" 
    . "showballoontip: " . showballoon . "`n" 
    . "showfinishedbox: " . showfinished . "`n"  
    . "showballoontip: " . showballoon . "`n"  
    . "maximum filenamelength: " . par . "`n" 
    . "logging: " . loggingvar . "`n`n`n" 
    . "Check that all parameters are ok")
  
  ifinstring, par, ERROR
  {
    msgbox Config.ini is corrupted! `n Exit!
    exitapp
  }
  getfilelength(par) ;initialisieren der maximalen DateinamenlÃ¤nge
  
  if(loggingvar == 1)
  {
    logging("", true)
  }
  
  urls := urls . "`n"
  
  anzurls := counturls(urls)
  showballoon(0, "Buch", anzurls, showballoon)
  
  loop
  {

    stringgetpos, pos, urls, `n
    if pos < 1 then
      break
    stringleft, url, urls, pos
    stringtrimleft, urls, urls, pos + 1 ;to remove leading new line `n
          
    url := getmainurl(url)
    logging("`n" . A_Now . "; " . url)
    if strlen(url) < 4
    {
      debugmsg("URL will be ignored: " . url . "`n`nSpringerLoader will continue")
      logging("; url too short")
      continue ;errorneous url, continue with next one
    }
    
    ;httrack generates dynamic index file names
    ifexist, %a_scriptdir%\*.html.readme
      filedelete, %a_scriptdir%\*.html.readme
      ifexist, %a_scriptdir%\index*.html
      filedelete, %a_scriptdir%\index*.html
    ;par25= -V "delete *.html.readme ren $0 index-2.html"
    download(url, par1, par2)
    
    ;for httrack
    ifexist, %a_scriptdir%\*.html.readme
    {
      Loop %a_scriptdir%\*.html.readme
      {
        filedelete, %a_loopfilename%
        stringtrimright, fname, a_loopfilename, strlen(".readme")
        filemove, %fname%, index-2.html, 1
        break
      }
    }
    
    ;for wget
    Loop %a_scriptdir%\index*.html*mp*
    {
      filemove, %a_loopfilename%, %a_scriptdir%\contents ;will be correctly renamed at extract
      break
    }

    wgetExtract()
    
    filegetsize, groe, %a_scriptdir%\index-2.html, k
    if(errorlevel)
    {
      logging("; download failed")
      debugmsg("Book website could not be downloaded `n"
        . "File is missing: " . a_scriptdir . "\index-2.html `n" 
        . "from URL: " . url
        . "`nPlease review HTTrack log file: " . a_scriptdir . "\hts-log.txt"
        . "`nand Wget log file: " . a_scriptdir . "\wget-log.txt"
        . "`n`n`nSpringerLoader will continue")
        ;here something should be done, that you can try reading a file manually!
      continue
    }
    else if groe < 10 ;Fehlerhaft!
    {
      debugmsg("File will be ignored: " . a_scriptdir . "\index-2.html `n" 
        . "from URL: " . url 
        . "`nPlease review HTTrack log file: " . a_scriptdir . "\hts-log.txt"
        . "`nand Wget log file: " . a_scriptdir . "\wget-log.txt"
        . "`n`nThis file is very small and may contain no book`nSpringerLoader will continue")
      logging("; main file too small")
      continue ;do not delete files for debugging!
    }
    downloadfromparsing(par1, par2)
  }
  
  showballoon(-99, "Buch") ;Finished balloon tip

  if(!showfinished && showballoon)
    sleep, 5005
  
  if (showfinished)
    msgbox Finished!
exitapp
}
;---




downloadfromparsing(par1, par2)
{
  static anzfinished = 0
  
  ;stringgetpos, pos, url, /, R2
  ;stringleft, url2, url, pos
  ;msgbox, %url2%

  ;FileSelectFile, file
  
  file := a_scriptdir . "\index-2.html" ;es gibt keine index.html
  if(checkaccess(file, par1, par2))
  { 
    destfolder := ExtractBookTitle(par1, par2)

    ;cover image
    cover := extractcover(file)
    if(strlen(cover) > 2) ;if there is no cover, download nothing
    {
      title := "http://www.springerlink.com" . cover
      download(title, par1, par2)
      trymovefile(destfolder, "cover-large.gif", "cover.gif", 98)
    }

    i = 1
    ;"/content/jq516w7924701460/fulltext.pdf"
    dataFound := 0
    Loop, read, %file%
    {
      line := A_LoopReadLine
      
      
      if(dataFound > 0) ;prevent that there are links multiple found; but if a line is too long, try searching the next 2 lines too
      {
        dataFound := dataFound + 1
        if(dataFound > 3)
        {
          break ;stop searching pdfs in this file
        }
      }
      
      if(instr(line, ".pdf")) ;check if even one pdf is there.... prevents false alarm
      {
      
        ;behave like a state machine:
        ;first find url and save into relUrl
        ;next: if relUrl is not empty write chaptername
        ;clear relUrl
        ;again
        ;hell yeah - it is a tiny state machine

        dataFound := dataFound + 1

        fturl := ""
        Loop, parse, line,<>,
        {
          data := A_LoopField
          if(strlen(fturl) > 0) ;chapter found
          {
            title := correctfile(data)
            download(fturl, par1, par2)
            ;workaround for httrack - not really nice but should work

            Loop %a_scriptdir%\fulltext*.pdf*
            {
              trymovefile(destfolder, a_loopfilename, title . ".pdf", i, fturl)
              break
            }
            
            Loop %a_scriptdir%\front-matter*.pdf*
            {
              trymovefile(destfolder, a_loopfilename, "front-matter.pdf", i, fturl)
              break
            }
            Loop %a_scriptdir%\back-matter*.pdf*
            {
              trymovefile(destfolder, a_loopfilename, "back-matter.pdf", i, fturl)
              break
            }
            
            ;get special files, zip, rar and iso
            ;MoveSpecialFiles(title)  ;-not implemented yet

            i:= i + 1
            fturl := ""
          }
          else
          {
            fturl := parseUrl(data)
          }
          
        } ;end parse
        
      } ;end .pdf check
    }



    ;zuletzt noch Index verschieben

    trymovefile(destfolder, "index-2.html", "about.html", 99)
    
    anzfinished := anzfinished + 1
    
    showballoon(anzfinished, booktitle)
    logging("; ok")
  } ; end of access check
  else
  {
    ;FileDelete, %file%
    logging("; check access failed")
  }

  return
}
;----------------------

ExtractBookTitle(par1, par2)
{
  file := a_scriptdir . "\index-2.html" ;es gibt keine index.html
  booktitle := extracttitle(file)
  booktitle := debuginput("Book title ok? `nThe book folder will be named by book title. `n`nIt must be at least 4 characters long!`n"
    . "If book folder already exists it will be numbered.", booktitle, 4)
  booktitle := correctfile(booktitle)
  if strlen(booktitle) < 4
  {
    debugmsg("This book will be ignored because book title is too short! `n" 
      . "(You should not see this message)")
    return
  }
   
  destfolder := trycreatefolder(booktitle)
  return destfolder
}

parseUrl(data)
{
  searchstring1:=".pdf"""
  searchstring2:=".zip""" ;dont know if this could happen
  searchstring3:=".rar"""
  searchstring4:=".iso"""
  searchstringcount = 1
 
  relUrl := ""
  loop, %searchstringcount%
  {
    if (instr(data, searchstring%a_index%) > 0)
    {
      stringtrimright, relUrl, data, 1 ;remove "
    }
  }
  if(strlen(relUrl) == 0)
  {
    stringgetpos, pos, data, /", R1
    if(pos>0)
    {
      stringtrimright, relUrl, data, 1 ;remove " 
      relUrl := relUrl . "fulltext.pdf"
    }
    if(pos==0)
      msgbox, pos0
  }
  
  ;the last value should not finish with " and is the url
  loop,parse, relUrl, "
  {
    retVal := "http://www.springerlink.com" . A_LoopField
  }
  
  return  retVal
}




download(url, par1, par2)
{
  url := debuginput("URL correct? Are all slashes correct? `n`nPlease check URL carefully!", url)
  ;cmd:="httrack.exe " . par1 . " " . url . " " . par2 . " " . a_scriptdir
  ;cmd:="cmd /c pause | httrack.exe " . par1 . " " . url . " " . par2 . " " . a_scriptdir ;working but not needed anymore
  cmd:=createdownloadcommand(url, par1, par2)
  cmd := debuginput("Command correct?", cmd)
  ;msgbox, %cmd%
  ;runwait, %cmd%
  runwait, %cmd%,,hide
  sleep, 500
  ;msgbox sleep
}

createdownloadcommand(url, par1, par2, downloader = 0, setTemporarily = 0)
{
  static chosen = 0
  cmd:=""
  if (downloader > 0 && setTemporarily == 0)
  {
    chosen := downloader
  }
  else
  {
    if (chosen == 1 && setTemporarily == 0)
      cmd:= """" . a_scriptdir . "\" . "httrack.exe"" " . par1 . " " . url . " " . par2 . " " . """" . a_scriptdir . """"
    else if (chosen == 2&& setTemporarily == 0)
      cmd:="""" . a_scriptdir . "\" . "wget.exe"" -o wget-log.txt " . url
    else if (downloader == 2 && setTemporarily == 1)
      cmd:="""" . a_scriptdir . "\" . "wget.exe"" -o wget-log.txt --spider " . url
    else
      msgbox bug?
  }
  return cmd
}

checkaccess(localfilewithpath, par1, par2, docheck = false)
{
  ;msgbox %localfilewithpath%
  ;if access check is not enabled this function will always return true
  static staticretval := false
  if (docheck)
  {
    staticretval := docheck ;if check is enabled it will always start with false
  }
  
  if(staticretval)
  {
    retval := false
    line := ""
    pos := 0
    loop, read, %localfilewithpath%
    {
      line := A_LoopReadLine
      pos := instr(line, "fulltext.pdf")
      if( pos > 0)
      {
        break
      }
    }
    if(pos > 0)
    {
      stringtrimright, line, line, strlen(line) - pos - strlen("fulltext.pdf") + 1
      ;msgbox, %line%
      strr := "href"
      StringGetPos, posit, line, href, r1

      stringright, line, line, strlen(line) - posit - 6 ;search reverse
      url := "http://www.springerlink.com" . line
      ;msgbox %url% %posit%
      cmd := createdownloadcommand(url, par1, par2, 2, 1)
      runwait, %cmd%,,hide
      sleep, 500
      loop, read, %a_scriptdir%\wget-log.txt
      {
        if(instr(A_LoopReadLine, "Length") > 0)
        {
          if(instr(A_LoopReadLine, "unspecified") < 1)
            retval := true
        }
      }
    }
  }
  else
  {
    retval := true
  }
  return retval
}

getmainurl(url)
{
  stringgetpos, pos, url, doi.org
  if pos > 0 
  {
    stringgetpos, urlpos, url, /, R
    if strlen(url) - urlpos = 1
      stringleft, url, url, strlen(url) - 1
    stringgetpos, urlpos, url, /, R
    stringright, url2, url, strlen(url) - urlpos
    url2 := "http://www.springerlink.com/content" . url2
  }  
  else
  {
    IfInString, url, openurl
    {
      stringtrimright, url, url, 1
      stringgetpos, isbnpos, url, =,R1
      length := strlen(url) - isbnpos - 1
      stringright, isbn, url, %length%
      url2 := "http://www.springerlink.com/content/" . isbn 
      ;msgbox, %url2%
    }
    else
    {
      stringgetpos, urlpos, url, content/
      urlpos2 := urlpos + 9 ;offset for word content/
      stringgetpos, urlpos, url, /,, urlpos2  ;find next / relative to content/
      if ErrorLevel ;if user erases all / after isbn
      {
        url2 := url . "/"
        stringgetpos, urlpos2, url2, /,, urlpos2
        stringleft, url2, url2, urlpos2
      }
      else
        stringleft, url2, url, urlpos
    }
  }
  if (strlen(url2) < 4 && !getdebugstatus())
    inputbox, a, Error, Error at following URL: `n`nSoftware will continue with next URL!,,,,,,,,%url%
  else
    url2 := url2 . "/contents/?MUD=MP"
  url2 := debuginput("URL correct? `nIt must look like this:`n" 
    . "http://www.springerlink.com/content/978-1-234-56789-0/contents/?MUD=MP" 
    . "`n`nCheck Slashes `n`nPlease check URL carefully!", url2)
  return url2
}

extracttitle(file)
{
  i = 0
  ;<dt>Title</dt>
  Loop, read, %file%
  {
    if (instr(A_LoopReadLine, "<dt>Title</dt>") > 0)
    {
      line := a_loopreadline
      break
    }
  }
  
  stringgetpos, pos, line, <dt>Title</dt>
  stringright, title, line, strlen(line) - pos - strlen("<dt>Title</dt>")
  
  
  loop
  {
    stringgetpos, pos, title, >
    if pos < 5
      stringright, title, line, strlen(title) - pos - 1
    else
      break
  }
  
  stringgetpos, pos, title, <
  stringleft, title, title, pos
  title := correctfile(title)
  
  return title
}

correctfile(title)
{
  ;http://de.autohotkey.com/forum/post-52193.html&sid=bdee8fd290daaebc43c34bf2ce147aa6#52193
  a = ,
  StringReplace, title, title, %A_SPACE%, _, All
  StringReplace, title, title, %A_Tab%, _, All
  StringReplace, title, title, ÃƒÂ¤, ae, All
  StringReplace, title, title, ÃƒÂ„, Ae, All
  StringReplace, title, title, ÃƒÂ¼, ue, All
  StringReplace, title, title, ÃƒÂœ, Ue, All
  StringReplace, title, title, ÃƒÂ¶, oe, All
  StringReplace, title, title, ÃƒÂ–, Oe, All
  
  StringReplace, title, title, ÃƒÂŸ, ss, All
  StringReplace, title, title, %a%, , All ;kill comma
  
  StringReplace, title, title, Ã¤, ae, All
  StringReplace, title, title, Ã„, Ae, All
  StringReplace, title, title, Ã¼, ue, All
  StringReplace, title, title, Ãœ, Ue, All
  StringReplace, title, title, Ã¶, oe, All
  StringReplace, title, title, Ã–, Oe, All
  
  StringReplace, title, title, ÃŸ, ss, All
  
  ;even more problems: http://en.wikipedia.org/wiki/Filename
  a = :
  StringReplace, title, title, %a%, _, All
  a = \
  StringReplace, title, title, %a%, _, All
  a = /
  StringReplace, title, title, %a%, _, All
  a = ?
  StringReplace, title, title, %a%, _, All
  a = `%
  StringReplace, title, title, %a%, _, All
  a = *
  StringReplace, title, title, %a%, _, All
  a = |
  StringReplace, title, title, %a%, _, All
  a = ""
  StringReplace, title, title, %a%, _, All
  a = <
  StringReplace, title, title, %a%, _, All
  a = >
  StringReplace, title, title, %a%, _, All
  ;a = .
  ;StringReplace, title, title, %a%, _, All
  
  ;replace any other 
  title2 := regexreplace(title, "[^a-zA-Z0-9_.-]", "_")
  title := title2
  ;cut very long file names after x chars
  len := getfilelength()
  ;maybe if file is too long the extension will be killed
  ;stringright, ext, title, 4
  stringleft, title, title, %len%
  ;title := title . ext
  return title
}

extractcover(file)
{
  i = 0
  ;(/content/u6l5p0/cover-medium.gif)
  Loop, read, %file%
  {
    if (instr(A_LoopReadLine, "cover-") > 0)
    {
      line := a_loopreadline
        stringgetpos, pos, line, ), R
        stringleft, title, line, pos
        stringgetpos, pos, title, (, R
        stringright, title, title, strlen(title) - pos-1
        
        ;even large cover is availible; download it!
        stringleft, title, title, strlen(title) - strlen("medium.gif")
        title := title . "large.gif"
      break
    }
  } 
  return title
}

trycreatefolder(name)
{
  name := A_ScriptDir . "\" . name
  name2 := name
  i := 0
  if !FileExist(name2)
    filecreatedir, %name2%
  else
  {
    i := 0
    loop
    {
      i := i + 1
      
      if i < 10 ;zweistellig sollte reichen
        name2 := name . "_0" . i
      else
        name2 := name . i
        
      if !FileExist(name2)
      {
        filecreatedir, %name2%
        break
      }
    }
  }
    
  return name2
}

trymovefile(path, sourcename, name, number, fturl = "")
{
  if(getdebugstatus())
  {
    if(fileexist(a_scriptdir . "\" . sourcename))
    {
      name := debuginput("File " . sourcename . " was found`n" 
        . "Please check destination file name`n" 
        . "`n`nThe file number will be: " . number, name)
      name := correctfile(name)
    }
    else
    {
      text :="File " . sourcename . " was NOT found`nfrom following source URL: " . fturl
        . "`nPlease review HTTrack log file: " . a_scriptdir . "\hts-log.txt"
        . "`nand Wget log file: " . a_scriptdir . "\wget-log.txt"
        . "`n`n`nMaybe you do not full access?"
      inputbox, a, Error, %text%,,,,,,,,%fturl%
    }
  }

  if number < 10 ;zweistellig sollte reichen
    name2 := "0" . number
  else
    name2 := number
  filemove, %a_scriptdir%\%sourcename%, %path%\%name2%_%name%
  filedelete, %a_scriptdir%\%sourcename%.readme ;RestmÃ¼ll von httrack entfernen
}

getfilelength(len = 0)
{
  static length = 0
  if (len <> 0)
    length := len
  return length
}

counturls(urls)
{
  i := 0
  loop
  {
    stringgetpos, pos, urls, `n
    if pos < 1 then
      break
    stringleft, url, urls, pos - 1
    stringtrimleft, urls, urls, pos + 1
    i := i + 1
  }
  return i
}


showballoon(anzfinished, buchname, uanzurls = 0, ushowballoon = 0)
{
  static anzurls = 0
  static showballoon = 0
  if (uanzurls <> 0)
  {
    anzurls := uanzurls
    showballoon := ushowballoon 

  }
  if ((showballoon > 0) && (anzfinished > 0))
  {
    stringleft, buchname, buchname, 20
    text := "[" . anzfinished . "|" . anzurls . "] " . buchname . "..."
    Traytip, , %text%, , 17
    SetTimer, RemoveTrayTip, 3000
  }
  
  if (anzfinished < -2)
  {
    text := "All finished!"
    Traytip, , %text%, , 17
    SetTimer, RemoveTrayTip, 5000
    
  }
}


RemoveTrayTip:
SetTimer, RemoveTrayTip, Off
TrayTip
return


getdebugstatus(debugstatus = 0)
{
  static status = 0
  if (debugstatus <> 0)
    status = debugstatus
    
  return status
}


debugmsg(text)
{
  if(getdebugstatus())
    msgbox %text%
}


debuginput(msg, defaulttext = "", minimumlength = 1)
{
  entered := 0
  
  if(getdebugstatus())
  {

    while (entered == 0)
    {
    inputbox, text,, %msg%,,550,,,,,,%defaulttext%
    if (ErrorLevel or (strlen(text) < minimumlength))
      entered := 0
    else
      entered := 1
    }

    return text
  }
  else
    return defaulttext
}

checkexistence(file)
{
  IfNotExist, %A_ScriptDir%\%file%
  {
    msgbox %A_ScriptDir%\%file% is missing
  }
}

wgetExtract()
{
  ;workaround for wget
  if fileexist(a_scriptdir . "\index-2.html") && (fileexist(a_scriptdir . "\index.html@MUD=MP") fileexist(a_scriptdir . "\contents"))
  {
    filedelete, %a_scriptdir%\index-2.html
  }
  if fileexist(a_scriptdir . "\index.html")
  {
    filemove, %a_scriptdir%\index.html, %a_scriptdir%\index-2.html.gz
    runwait, %a_scriptdir%\gunzip.exe -fd index-2.html.gz,,hide
    debugmsg("tried to extract html file")
  }
  if fileexist(a_scriptdir . "\contents")
  {
    filemove, %a_scriptdir%\contents, %a_scriptdir%\index-2.html.gz
    runwait, %a_scriptdir%\gunzip.exe -fd index-2.html.gz,,hide
    debugmsg("tried to extract html file")
  }
}

logging(text, setlogging = false)
{
  static loggingenabled := false
  if(setlogging)
  {
    loggingenabled := setlogging
  }
  if(loggingenabled)
  {
    FileAppend, %text%, %a_scriptdir%\sload.log
  }
  

}

;not working atm... not implemented
licensetest()
{
  cmd := a_scriptdir . "\" . "wget.exe -o wget-log.txt " . "http://www.springerlink.com"
  runwait, %cmd%, %a_scriptdir%, hide
  sleep, 500
  filedelete, %a_scriptdir%\license.txt
  wgetExtract()
  Loop, read, %a_scriptdir%\index-2.html
  {
      IfInString, A_LoopReadLine, <ul id="Footer">
      {
        ind := a_index + 1
        filereadline, line, %a_scriptdir%\index-2.html, %ind%
        fileappend, %line%`r`n, %a_scriptdir%\license.txt
        ind := ind + 1
        filereadline, line, %a_scriptdir%\index-2.html, %ind%
        fileappend, %line%`r`n, %a_scriptdir%\license.txt
        ind := ind + 1
        filereadline, line, %a_scriptdir%\index-2.html, %ind%
        fileappend, %line%`r`n, %a_scriptdir%\license.txt
        ind := ind + 1
        filereadline, line, %a_scriptdir%\index-2.html, %ind%
        fileappend, %line%`r`n---, %a_scriptdir%\license.txt
        
        break
      }
  }
}